当我使用debug="false"
模式和BundleTable.EnableOptimizations = true
发布我的网站时
对于捆绑的脚本和样式,服务器返回以下异常,而请求仅针对非授权请求!但是,如果我使用debug="true"
运行应用程序或用户已登录(通过发布模式下的表单身份验证),则不会发生异常,并且每个都可以正常工作。
我认为捆绑和身份验证之间应该有关系!!如异常所示。
有什么问题?
我的捆绑代码:
public static void RegisterBundles(BundleCollection bundles)
{
StyleBundle bundleStyles = new StyleBundle("~/bundles/styles/");
bundleStyles.Include(
"~" + Paths.Scripts.AdminSkin.css.reset_css,
"~" + Paths.Scripts.AdminSkin.css.common_css,
"~" + Paths.Scripts.AdminSkin.css.form_css,
//do not move this line to blow
"~" + Paths.Scripts.site.css.standard_css,
"~" + Paths.Scripts.AdminSkin.css.standard_css,
"~" + Paths.Scripts.AdminSkin.css.special_pages_css,
//"~" + Paths.Scripts.AdminSkin.css.simple_lists_css,
//"~" + Paths.Scripts.AdminSkin.css.block_lists_css,
//"~" + Paths.Scripts.AdminSkin.css.planning_css,
//"~" + Paths.Scripts.AdminSkin.css.table_css,
//"~" + Paths.Scripts.AdminSkin.css.calendars_css,
//"~" + Paths.Scripts.AdminSkin.css.wizard_css,
//"~" + Paths.Scripts.AdminSkin.css.gallery_css,
"~" + Paths.Scripts.site.css.login_css,
"~" + Paths.Scripts.site.css.site_css,
"~" + Paths.Scripts.site.css.tables_css,
"~" + Paths.Scripts.site.css.standard_fa_css,
"~" + Paths.Scripts.site.css.theme_selector_css,
"~" + Paths.Scripts.jquery_ui_1_9_2.css.redmond.jquery_ui_1_9_2_custom_css,
"~" + Paths.Scripts.ImageGallery.wt_rotator_css,
"~" + Paths.Scripts.ImageGallery.default_css,
"~" + Paths.Scripts.calendar.aqua.theme_css
);
ScriptBundle bundleScripts = new ScriptBundle("~/bundles/scripts/");
bundleScripts.Include(
//Admin Skin Scripts
"~" + Paths.Scripts.AdminSkin.js.old_browsers_js,
"~" + Paths.Scripts.AdminSkin.js.libs.jquery_hashchange_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_accessibleList_js,
"~" + Paths.Scripts.AdminSkin.js.searchField_js,
"~" + Paths.Scripts.AdminSkin.js.common_js,
"~" + Paths.Scripts.AdminSkin.js.standard_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_tip_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_contextMenu_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_modal_js,
"~" + Paths.Scripts.AdminSkin.js.list_js,
//"~" + Paths.Scripts.AdminSkin.js.libs.jquery_dataTables_min_js,
//jquery plug ins
"~" + Paths.Scripts.jquery_ui_1_9_2.js.jquery_ui_1_9_2_custom_js,
"~" + Paths.Scripts.jquery_cookie.jquery_cookie_js,
"~" + Paths.Scripts.site.js.site_js,
"~" + Paths.Scripts.site.js.clock_js,
"~" + Paths.Scripts.site.js.size_js,
"~" + Paths.Scripts.site.js.cookie_manager_js,
//devexpress related
"~" + Paths.Scripts.site.js.devexpress_theme_js,
"~" + Paths.Scripts.site.js.devexpress_controls_js,
//chart scripts
"~" + Paths.Scripts.Highstock_1_2_5.highstock_src_modified_js,
"~" + Paths.Scripts.Highstock_1_2_5.exporting_js,
"~" + Paths.Scripts.Highstock_1_2_5.highcharts_more_js,
"~" + Paths.Scripts.site.js.chart_fa_js,
//calendar scripts
"~" + Paths.Scripts.calendar.jalali_js,
"~" + Paths.Scripts.calendar.calendar_js,
"~" + Paths.Scripts.calendar.calendar_setup_js,
"~" + Paths.Scripts.calendar.calendar_fa_js,
"~" + Paths.Scripts.calendar.calendar_en_js,
//image gallery scripts
"~" + Paths.Scripts.ImageGallery.js.jquery_wt_rotator_min_js,
"~" + Paths.Scripts.ImageGallery.js.jquery_easing_1_3_min_js,
"~" + Paths.Scripts.ImageGallery.js.preview_js
);
if (RequestCachedItems.Setting.UseGoogleMap)
{
}
else
{
//leaflet map script
bundleScripts.Include("~" + Paths.Scripts.leaflet_0_7.leaflet_src_js);
//leaflet map style
bundleStyles.Include("~" + Paths.Scripts.leaflet_0_7.leaflet_css, new CssRewriteUrlTransform());
}
ScriptBundle bundleLiveScripts = new ScriptBundle("~/bundles/livescripts/");
bundleLiveScripts.Include(
"~" + Paths.Scripts.signalr.jquery_signalR_2_0_0_min_js,
"~" + Paths.Scripts.signalr.hubs_js,
"~" + Paths.Scripts.liveControls.connectionManager_js,
"~" + Paths.Scripts.liveControls.liveControls_js,
"~" + Paths.Scripts.liveControls.liveTables_js
);
bundles.Add(bundleStyles);
bundles.Add(bundleScripts);
bundles.Add(bundleLiveScripts);
BundleTable.EnableOptimizations = true;
}
例外:
[NullReferenceException:对象引用未设置为的实例 object。] System.Web.HttpContext.RequestRequiresAuthorization() +18 System.Web.Caching.OutputCacheModule.OnLeave(Object source,EventArgs eventArgs)+9606196
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+69
答案 0 :(得分:1)
我在Application_PostAuthenticateRequest
中使用了Global.ascx.cs
并使HttpContext.Current.User
为空。我评论说这条线和问题已经解决了。
public class Global : HttpApplication
{
FormsAuthenticationTicket ticket;
ExtendedUser extendedUser;
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
//cause of problem
//HttpContext.Current.User = null;
if (FormsAuthentication.CookiesSupported)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
try
{
ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
using (UnitOfWork unit = new UnitOfWork())
{
if (ticket.Name == SecurityHelpers.SuperAdminUserName)
{
SecurityHelpers.GetSuperAdminUser(unit);
}
else
{
extendedUser = SecurityHelpers.GetUser(unit, ticket);
}
}
if (extendedUser != null)
{
string[] roles = extendedUser.Group.GroupRoles.Select(a => a.Role.RoleName).ToArray();
HttpContext.Current.User = new GenericPrincipal(new MyFormsIdentity(extendedUser), roles);
}
}
catch (Exception)
{
// Decrypt method failed.
}
}
}
else
{
// throw new HttpException("Cookieless Forms Authentication is not " +
// "supported for this application.");
}
}
}