When ever i publish my web site with debug="false" mode and BundleTable.EnableOptimizations = true
the server returns the following exception for bundled scripts and styles while requests are just for non authorized requests! But if I run application with debug="true" or user is logged in (via forms authentication in release mode) the exception does not occur and every thins works just fine.
I think there should be a relation between bundling and authentication!! as the exception indicates.
What is wrong?
my bundling codes:
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;
}
the exception:
[NullReferenceException: Object reference not set to an instance of an
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
I've used Application_PostAuthenticateRequest in Global.ascx.cs
and made HttpContext.Current.User null. I've commented that line and the problem is solved.
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.");
}
}
}
Related
Hello I am using Vaadin 8 and Vaadin charts 4.0 and am trying to format one of the data axis of the chart to different date time formats depending on user format input and locale. I try to inject the moment.js library and get a reference exception saying that moment variable does not exist. I have tried 2 different approaches which I list below:
(1) Use the #JavaScript annotation to inject moment.js.
#JavaScript({"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js", "https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.13/moment-timezone-with-data-2012-2022.min.js"})
#WebServlet(urlPatterns = "/*", name = "IeUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = IeUI.class, productionMode = true, heartbeatInterval = 500, closeIdleSessions = false, widgetset = "softcom.ievaadin.AppWidgetSet")
public static class IeUIServlet extends VaadinServlet implements SessionInitListener {//, SessionDestroyListener {
#Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
// Add any system level init here
//Main.initSystem();
}
#Override
public void destroy() {
super.destroy(); //To change body of generated methods, choose Tools | Templates.
Main.destroy();
}
#Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().getSession().setMaxInactiveInterval(-1);
}
}
And the one where set the formatter
YAxis ya = new YAxis();
String js = "function() {";
js += "try {"
+ "var g = moment.tz(\"2014-06-01 12:00\", \"America/New_York\");"
+ "alert(g);"
+ "return g;}"
+ "catch(e) {"
+ "alert(e);}}";
ya.getLabels().setFormatter(js);
(2) I try to append the script tag at the head in the function itself.
String js = "attempt {"
+ "var script = document.createElement('script');"
+ "script.src = \"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js\";"
+ "document.head.appendChild(script);"
+ "} catch(e) {"
+ "alert('first one'); }"
+ "try {"
+ "var b = moment().format();"
+ "return b;"
+ "} catch (e) {"
+ "alert(e); }";
JavaScript.getCurrent().execute(attempt);
String js = "function() {";
js += "try {"
+ "var g = moment.tz(\"2014-06-01 12:00\", \"America/New_York\");"
+ "alert(g);"
+ "return g;}"
+ "catch(e) {"
+ "alert(e);}}";
ya.getLabels().setFormatter(js);
Any help would be appreciated.
You can inject the script tag in the head of the document by registering a BootstrapListener in your IeUIServlet:
#Override
protected void servletInitialized() {
getService().addSessionInitListener(event -> {
event.getSession().addBootstrapListener(new BootstrapListener() {
#Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
response.getDocument().head().append("<script src=\"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js\"></script>");
response.getDocument().head().append("<script src=\"https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.13/moment-timezone-with-data-2012-2022.min.js\"></script>");
}
#Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
}
});
});
}
And preprend $wnd to moment in your javascript, like this:
var g = $wnd.moment.tz(\"2014-06-01 12:00\", \"America/New_York\");
Some possible (pure Vaadin) approaches:
1) Customizing the labels: mychart.getConfiguration().getxAxis().setDateTimeLabelFormats(dateTimeLabelFormats);
2) Customizing the timezone & offset:
JavaScript.getCurrent().execute("Highcharts.setOptions({\n" +
" global: {\n" +
" useUTC: true,\n" +
" timezoneOffset: "+ timezoneOffsetInMinutes + "\n" +
" }\n" +
"});");
3) Configuring the tooltip with a user-friendly datetime format:
DataSeriesItem dataSeriesItem;
Date datetime = ...;
if (useUTC) {
dataSeriesItem = new DataSeriesItem(datetime.toInstant(), value);
} else {
dataSeriesItem = new DataSeriesItem(datetime, value);
}
dataSeriesItem.setId(xxxxx); // <= string with desired user/locale-dependant formatting of related datetime
guys! I'm trying to append folder to user.home property. It working nice, while I'm using just one additional folder. But when I try to make another two additions (so it looks like user.home+folder1+folder2+folder3) it trows ---
java.lang.IllegalArgumentException: Folder parameter must be a valid folder---
. My though that there is some restriction, but can't find out where.
String fullRoute = null;
File homeDir = new File("MLog");
if (!SiteCo.getEditor().getText().isEmpty() &&
!InciDate.getEditor().getText().isEmpty()) {
homeDir.mkdirs();
fullRoute = System.getProperty("user.home") + File.separator +
//SaveVarTo.getLastVisitedDirectory() +
SaveVarTo.AddPath(SiteCo.getValue().toString()) +
File.separator + SaveVarTo.AddPath(InciDate.getValue().toString());
}
else {homeDir.mkdirs();
// File.separator+homeDir.toString() - without it
fullRoute =
System.getProperty("user.home")+File.separator+homeDir.toString();}
System.out.println(fullRoute);
fileChooser.setInitialDirectory(new File(fullRoute));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("XML Files", "*.xml"));
//sample of method
public class Variables{
public String AddPath(String name) {
if (!name.isEmpty()) {
//File nou = new File(getLastVisitedDirectory() +"\\" + name);
File nou = new File(name);
if (!nou.exists()) {
nou.mkdirs();
} else {
System.out.println("Folder already exists");
}
}
else{name = null;}
return name;
}}
String fullRoute = null;
File homeDir = new File(System.getProperty("user.home"));
if (SiteCo.getValue() !=null && InciDate.getValue() !=null) {
System.out.println(SaveVarTo.getMainFolder());
fullRoute = homeDir + File.separator + SaveVarTo.getMainFolder() +
File.separator + SiteCo.getValue().toString() +
File.separator + InciDate.getValue().toString();
} else {
fullRoute = homeDir.toString();
}
System.out.println(fullRoute);
File fhd = new File(fullRoute);
if (!fhd.exists())
fhd.mkdirs();
fileChooser.setInitialDirectory(fhd);
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("XML Files", "*.xml"));
I have many files in one directory, My app, must move some files to another directory. When I did this, first time works fine, but after that I have a exception like:
System.IO.IOException: process cannot access the file because another process is using the file.
I close windows explorer, or any program, avoiding the use of the file, but the problem persists.
I move files in this way:
private void ExtractosRemover()
{
string dirOrigen = '\\' + #"\" + servidor + #"\" + "EEQ_" + User.Identity.Name.ToString() + #"\";
string dirDestin = '\\' + #"\" + servidor + #"\" + "FacturasMatch_" + User.Identity.Name.ToString() + #"\";
try
{
foreach (GridViewRow grd_Row in this.gvwExtractosMatch.Rows)
{
File.Move(System.IO.Path.Combine(dirOrigen, clean(grd_Row.Cells[7].Text) + ".xml"), dirDestin);
}
}
catch (FileNotFoundException)
{
}
catch (IOException ioex)
{
lbl_UbiDevMensaje.Text = string.Empty;
lbl_UbiDevMensaje.Text = ioex.ToString();
}
}
For the names of the files, I read a gridview, and I add the extensions.
I don't know what is happening,
Please, I hope somebody can help me.
Thanks in advance.
best regards
Solved,
Using server map
private void ExtractosRemover()
{
string dirOrigen = "~/" + "EEQ_" + User.Identity.Name.ToString() + "/";
string dirDestin = "~/" + "FacturasMatch_" + User.Identity.Name.ToString() + "/";
foreach (GridViewRow grd_Row in this.gvwExtractosMatch.Rows)
{
try
{
File.Move( //Mover xml
Server.MapPath(dirOrigen + clean(grd_Row.Cells[7].Text) + ".xml"),
Server.MapPath(dirDestin + clean(grd_Row.Cells[7].Text) + ".xml")
);
File.Move( //Mover pdf
Server.MapPath(dirOrigen + "RIDE_" + clean(grd_Row.Cells[7].Text) + ".pdf"),
Server.MapPath(dirDestin + "RIDE_" + clean(grd_Row.Cells[7].Text) + ".pdf")
);
}
catch (FileNotFoundException)
{ }
}
}
I am working on a Facebook application and I can successfully get the user's info in JSON after authorizing. However, when I refresh the page, I'm redirected to Facebook for OAuth when I thought that the authorization had already taken place. I had understood that I only needed an access token, subsequently.
if (fbData != null)
{
if (fbData.user_id == null)
{
var redirURL = Request.Url.Scheme + "://" + fbAuthURL.Replace("[APPID]", appId).Replace("[REDIRECT]", (Request.Url.Scheme + "://" + canvasPage));
Response.Write("<script type=\"text/javascript\"> " + Environment.NewLine +
"top.location.href=\"" + redirURL + "\";" + Environment.NewLine +
"</script>");
Response.Write("Redirect URL for Authorization : " + redirURL);
}
else
{
if (isReady == true)
{
MyWebRequest userRequest = new MyWebRequest("https://graph.facebook.com/me?access_token=" + accessToken);
string userInfo = userRequest.GetResponse();
//Response.Write(userInfo);
FBAuth fuser = new FBAuth();
UserInfo oUser = fuser.GetUserInfo(userInfo);
}}}
How can I handle it?
On a testing server my URL=
http:
//scantdev04:8086/ActivityReport.aspx
I want to prefill a new URL with query data and pass it to the new url:
string sUrl = sRelativePath + "?Organization=" + sOrganization
+ "&&StartDate=" + sStartDate
+ "&&EndDate=" + endDate;
string displayScript = "" +
"window.open('" + sUrl + "', 'DisplayReport', " +
"'width=1200, height=800, toolbar=yes, menubar=yes, resizable=yes, scrollbars=yes')" +
"";
Pretty straight forward.
On dev box, localhost, it is all good.
But in test, the URL spits out like:
http://www.displayreport.aspx/?Organization=Correctional%20Alternatives,%20Inc&&StartDate=09-01-2009&&EndDate=10/6/2009%2012:00:00%20AM
How do I fix the www. that is now there and repeat the "http://scantdev04:8086/"
I would rather not push this to the web.config but will if necessary.
Where does your sRelativePath string come from?
Found this and it seems to work:
old version:
string sRelativePath = Request.ApplicationPath + "/DisplayReport.aspx";
Now changed to :
string sRelativePath = GetWebAppRoot() + "/DisplayReport.aspx";
GetWebRoot() :
string host = (HttpContext.Current.Request.Url.IsDefaultPort) ?
HttpContext.Current.Request.Url.Host : HttpContext.Current.Request.Url.Authority;
host = String.Format("{0}://{1}", HttpContext.Current.Request.Url.Scheme, host);
if (HttpContext.Current.Request.ApplicationPath == "/")
return host;
else
return host + HttpContext.Current.Request.ApplicationPath;