Kal*_*exx 4 c# cookies dotnetnuke ashx
我看到一个非常奇怪的问题,只有非管理用户才会发生.
当用户登录并访问一个页面时,它们将从系统中注销.页面完成加载,就像他们已登录一样,但一旦他们尝试任何其他操作(包括刷新浏览器页面),他们就会被认为未登录并显示登录提示.
打开fiddler,我可以看到服务器的响应之一包含以下内容:
响应发送了71个字节的Cookie数据:Set-Cookie:portalaliasid =; expires = Sat,08-May-1982 17:26:06 GMT; 路径= /; 仅Http
响应发送69个字节的Cookie数据:Set-Cookie:portalroles =; expires = Sat,08-May-1982 17:26:06 GMT; 路径= /; 仅Http
响应发送69个字节的Cookie数据:Set-Cookie:.DOTNETNUKE =; expires = Tue,12-Oct-1999 04:00:00 GMT; 路径= /; 仅Http
响应发送了27个字节的Cookie数据:Set-Cookie:language =; 路径= /; 仅Http
响应发送33个字节的Cookie数据:Set-Cookie:authentication =; 路径= /; 仅Http
当我访问我的自定义ashx Web调用时,似乎总会发生这种情况.进行此调用的代码是以下javascript:
$('#lstStates').empty();
var selectedRegions = $('select[id*=lbxRegions]').val();
// Get the list of states for the selected regions
$.ajax({
url: '/DesktopModules/MyModule/ashx/GetStatesForRegions.ashx',
data: { regions: selectedRegions },
dataType: 'json',
success: function (data) {
if (IsArray(data)) {
for (var state in data) {
$('#lstStates').append('<option>' + data[state] + '</option>');
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
ashx中的代码是
public class GetStatesForRegions : IHttpHandler
{
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
// Get the list of region ids from the GET request
string[] ids;
string regionsArray = context.Request["regions[]"] ?? string.Empty;
ids = regionsArray.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
using (var dbContext = new MyDataContext())
{
string[] states;
var query = dbContext.Schools.Where(x => x.PodRegionId != null);
if (ids != null && ids.Length > 0)
query = query.Where(x => ids.Contains(x.PodRegionId.ToString()));
states = query.Select(x => x.xosAddress.State)
.Distinct()
.OrderBy(x => x)
.ToArray();
context.Response.Write(JsonConvert.SerializeObject(states));
context.Response.End();
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么清除我的相关cookie并注销非管理员用户?
发生这种情况是因为用户仅在子门户中定义,但是在父门户中发生了对ASHX的请求(从DNN的角度来看).当DNN收到请求时,它会看到您"切换了门户",不再具有有效身份,并删除了您的身份验证信息.超级用户不会这样做,因为它们在两个门户网站上都有一个有效的身份.
要解决此问题,您需要使用门户网站ID为请求添加查询字符串参数.这让我们的DNN消除了请求的歧义并保持您的身份验证不变:
$.ajax({
url: '/DesktopModules/MyModule/ashx/GetStatesForRegions.ashx?portalId=' + <%:PortalId%>,
....
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2045 次 |
| 最近记录: |