モジュールが aspx ページではなくユーザー コントロールとして開発されているため、DotNetNuke 6 は WebMethods をサポートしていないようです。
DNN ユーザー モジュールからそのモジュールを含むページに JSON をルーティング、呼び出し、返すための推奨される方法は何ですか?
モジュールが aspx ページではなくユーザー コントロールとして開発されているため、DotNetNuke 6 は WebMethods をサポートしていないようです。
DNN ユーザー モジュールからそのモジュールを含むページに JSON をルーティング、呼び出し、返すための推奨される方法は何ですか?
この問題を処理する最善の方法は、カスタム Httphandler です。ベースラインとして、 Chris Hammonds の記事にある例を使用しました。
一般的な考え方は、カスタム HTTP ハンドラーを作成する必要があるということです。
<system.webServer>
<handlers>
<add name="DnnWebServicesGetHandler" verb="*" path="svc/*" type="Your.Namespace.Handler, YourAssembly" preCondition="integratedMode" />
</handlers>
</system.webServer>
また、従来のハンドラー構成も必要です。
<system.web>
<httpHandlers>
<add verb="*" path="svc/*" type="Your.Namespace.Handler, YourAssembly" />
</httpHandlers>
</system.web>
ハンドラー自体は非常に単純です。要求の URL とパラメーターを使用して、必要なロジックを推測します。この場合、Json.Net を使用して JSON データをクライアントに返しました。
public class Handler: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//because we're coming into a URL that isn't being handled by DNN we need to figure out the PortalId
SetPortalId(context.Request);
HttpResponse response = context.Response;
response.ContentType = "application/json";
string localPath = context.Request.Url.LocalPath;
if (localPath.Contains("/svc/time"))
{
response.Write(JsonConvert.SerializeObject(DateTime.Now));
}
}
public bool IsReusable
{
get { return true; }
}
///<summary>
/// Set the portalid, taking the current request and locating which portal is being called based on this request.
/// </summary>
/// <param name="request">request</param>
private void SetPortalId(HttpRequest request)
{
string domainName = DotNetNuke.Common.Globals.GetDomainName(request, true);
string portalAlias = domainName.Substring(0, domainName.IndexOf("/svc"));
PortalAliasInfo pai = PortalSettings.GetPortalAliasInfo(portalAlias);
if (pai != null)
{
PortalId = pai.PortalID;
}
}
protected int PortalId { get; set; }
}
http://mydnnsite/svc/timeへの呼び出しは適切に処理され、現在の時刻を含む JSON が返されます。