I am working with iFrame in webforms. However, I am getting a error like below:
I know how people solve it in .net core (like that in there : <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> ) but I couldn't find any kind of solution in webforms.
Well, you can certainly have some custom setting that tells you this is "development" or "some kind" of debug mode.
Then on page load you can do this:
if ("some kind of development mode")
{
this.pshow.Attributes.Add("src", "/PDF/web/viewer.html?file=" + strFWebPath);
}
else
{
this.pshow.Attributes.Add("src", "whatever here for pduction or release");
}
Related
In ASP.NET Boilerplate I am changing language like
English
It works properly on my local machine, but not on test server.
Also when I'm clicking it locally, sometimes there is abp.message.error with null content.
I have a few questions about that:
1) What is this URL (/AbpLocalization...), looks lika a controller, but there is no such thing in my code?
2) How can I find and debug it?
3) What may happen on another server that crashes it (on test server clicking button reloads state, but does not change language)
Solved!
What caused the problem was the fact, that the database on test server did not have one table that was in local database, and what's more important: this table was included in model transferred through Entity Framework to database. After adding table to test server everything works fine.
ASP.NET Boilerplate is an application framework built from modules, one of them being Localization module. Since it's open source you can change default behaviors, although I should not recommend doing it without really good reason.
Localization is part of the core package and it's located here: GitHub
I recommend you to use documentation and configure it to your needs. You can find localization documentation here: documentation.
And lastly, you should check your running configuration in the test environment, which is possibly faulted in some way. Another reason for error may be an issue with your ABP version.
AbpLocalizationController is located here in source code
src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs
And this is change culture code:
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
{
if (!GlobalizationHelper.IsValidCultureCode(cultureName))
{
throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!");
}
var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));
Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
cookieValue,
new CookieOptions {Expires = Clock.Now.AddYears(2)}
);
if (AbpSession.UserId.HasValue)
{
SettingManager.ChangeSettingForUser(
AbpSession.ToUserIdentifier(),
LocalizationSettingNames.DefaultLanguage,
cultureName
);
}
if (Request.IsAjaxRequest())
{
return Json(new AjaxResponse());
}
if (!string.IsNullOrWhiteSpace(returnUrl) && AbpUrlHelper.IsLocalUrl(Request, returnUrl))
{
return Redirect(returnUrl);
}
return Redirect("/"); //TODO: Go to app root
}
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs
If you want to debug this code, fork the project from github repo and add it to your solution. Replace your abp dll references with this local project references.
Meanwhile you didn't mention what the error say. To learn it check out website logs.
While developing in C# for ASP .net 4 in VS2013 using WebForms, I was implementing a custom security object that has been used through out of all my applications. With the upgrading from VS2010 to VS2013, I came to this error that bugged me so much....
Unable to cast object of type
'System.Security.Principal.WindowsIdentity' to type
'CustomSecurity.BusinessObject.EmployeeIdentity'
And the code location as follows:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//This is where it fails
EmployeeIdentity employeeIdentity = (EmployeeIdentity)HttpContext.Current.User.Identity;
}
}
This line of code worked in VS2010 but didn't work in VS2013. The code compiles but gives me this error during run time.
Things I have tried so far:
Converting the CustomSecurity.BusinessObject.EmployeeIdentity to .net 4 assembly
Changed code to use Page.User and I still get the same error
Read other posts in StackOverflow, no luck in finding an answer....
My Question:
What are other suggestions that may resolve my issue?
So from converting the code from VS2010 to VS2013, the changes I need was to add the following to the Web.config:
<system.webServer>
<modules>
<!-- Add a Custom Authentication module THIS NEEDS TO BE ADDED FOR IIS8 + .NET 4 -->
<add name="DHAAuthenticationModule" type=" DHA.CustomSecurity.BusinessObject.DHAAuthenticationModule, DHA.CustomSecurity.BusinessObject"/>
</modules>
</system.webServer>
The reason I am assuming is be the webServer needs to understand object definitions as well....
This fixed my error that I encountered. It was really specific I guess.
Any thoughts on this?
I've been trying to open a file in asp.net 5 and have not been having a lot of success.
In the past you used Server.MapPath or HostingEnvironment.ApplicationPhysicalPath. They are both gone in the OWIN based framework.
There is a HostingEnvironment class but it's in the System.Aspnet but it needs to be initialized by the hosting environment (it no longer has a static member for ApplicationPhysicalPath but I'm guessing the WebRoot member does that now. The problem is I can't find a reference to it anywhere.
I've also looked at Context.GetFeature<> but it doesn't seem to have any feature that would show the application path, just request and response related info. The code listing the features can be found here.
<snark>Is the ability to work with files a discontinued feature in ASP.NET?</snark>
There is also the possibility that I can't brain very well right now and missed something.
You can get it from the ApplicationBasePath property of Microsoft.Framework.Runtime.IApplicationEnvironment serivce.
Example: https://github.com/aspnet/Mvc/blob/9f1cb655f6bb1fa0ce1c1e3782c43a2d45ca4e37/test/WebSites/FilesWebSite/Controllers/DownloadFilesController.cs#L28
There are two approaches now:
using Microsoft.Extensions.PlatformAbstractions;
public Startup(IApplicationEnvironment appEnv)
{
// approach 1
var path01 = PlatformServices.Default.Application.ApplicationBasePath;
// approach 2
var path02 = appEnv.ApplicationBasePath;
}
I wanted to know if it was possible to keep the Session variable thought builds in a ASP.NET + C#?
I ask this because every time I make a minor change to my application and need to rebuild it, I need to login again and do a nunch of operation after that... it's taking a lot of my time.
If there is no way around I can set up a testing mode where I'll always be logged in, or automatize the log in procedure... but it would save me time to just keep the Session after a build.
You could change your test server to use the State Server or SQL Server session state modes, which will survive an application restart.
I have used this hack when I didn't want to deal with authentication during development:
protected void Page_PreInit(object sender, EventArgs e)
{
// Fake authentication so I don't have to create a damn Login page just for this.
System.Web.Security.FormsIdentity id = new FormsIdentity(new FormsAuthenticationTicket("dok", false, 30));
string[] roles = { "a" };
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
}
This is only going to work on the page you put it on, though you could add it to a base page.
You definitely have to remember to remove this before you promote the code to test/QA/UAT/prod!
This answer is community wiki so as not to generate any reputation, as it's effectively a reworking of DOK's answer. If you like it, please upvote DOK's answer.
#Dok, if you want to edit your answer to incorporate any of this, please do, and I'll gladly delete this answer. :)
DOK, as mentioned in my comments to your answer (and possibly some help for your own solution), you might want to do the following:
#if DEBUG //As mentioned by DOK in the comments. If you set debug to false when building for deployment, the code in here will not be compiled.
protected void Page_PreInit(object sender, EventArgs e)
{
bool inDevMode = false;
inDevMode = bool.Parse(ConfigurationManager.AppSettings["InDevMode"]); //Or you could use TryParse
if(inDevMode)
{
// Fake authentication so I don't have to create a damn Login page just for this.
System.Web.Security.FormsIdentity id = new FormsIdentity(new FormsAuthenticationTicket("dok", false, 30));
string[] roles = { "a" };
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
}
}
#endif
To further ensure that you do not accidentally deploy with this active, then you would have your app settings in seperate config files (as well as your debug section). If you use Web Deployment projects, then you can put your dev config settings in one file, and your live config files in another (this is usually dev.config and live.config!).
eg, in your web.config:
<appSettings file="dev.config"/>
In your dev.config:
<appSettings>
<add key="InDevMode" value="true" />
</appSettings>
In your live.config:
<appSettings>
<add key="InDevMode" value="false" />
</appSettings>
I need to change the app name based on what configuration I'm using in Visual Studio. For example, if I'm in Debug configuration, I want the app name to show as 'App_Debug' in the Application field in the Elmah_Error table. Does anyone have any experience with this? Or is there another way to do it?
This can now be done purely in markup. Just add an applicationName attribute to the errorLog element in the <elmah> section of the web.config file. Example:
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="connectionString" applicationName="myApp" />
I've tested this and it works both when logging an exception and when viewing the log via Elmah.axd.
In the case of the OP, one would imagine it can be set programatically too but I didn't test that. For me and I imagine for most scenarios the markup approach is sufficient.
By default, Elmah uses the AppPool's application GUID as the default application name. It uses this as the key to identify the errors in the Elmah_Error table when you look at the web interface that's created through it's HTTP Module.
I was tasked to explore this option for my company earlier this year. I couldn't find a way to manipulate this by default since Elmah pulls the application name from HttpRuntime.AppDomainAppId in the ErrorLog.cs file. You could manipulate it by whatever key you want; however, that is the AppPool's GUID.
With that said, I was able to manipulate the ErrorLog.cs file to turn Elmah into a callable framework instead of a handler based one and allow for me set the ApplicationName. What I ended up doing was modifying ErrorLog.cs to include a property that allowed me to set the name as below:
public virtual string ApplicationName
{
get
{
if (_applicationName == null) { _applicationName = HttpRuntime.AppDomainAppId; }
return _applicationName;
}
set { _applicationName = value; }
}
What you will probably need to do is adjust this differently and set the ApplicationName not to HttpRuntime.AppDomainAppId but, instead, a value pulled from the web.config. All in all, it's possible. The way I did it enhanced the ErrorLog.Log(ex) method so I could use Elmah has a callable framework beyond web applications. Looking back I wish I did the app/web.config approach instead.
One thing to keep in mind when changing the application name in Elmah. The http handler that generates the /elmah/default.aspx interface will no longer work. I'm still trying to find time to circle back around to such; however, you may need to look into creating a custom interface when implementing.