asp.net: load aspx file server side - c#

I have some aspx pages that dynamically generate xml (from backcode).
I want to load that xml to a XmlDocument on another page (server side).
But using XmlDocument.load(MapPath(path)) only loads text from file, backcode is not interpreted. Is there any way to load aspx page on the server as it would be viewed from the client?
Edit: problem is that when loaded by XmlDocument.load(MapPath(path)) backcode is not interpreted. I resolved this by just coping code that created the xml - but maybe there is some way to get aspx page on server the way it is viewed in client?

Related

Download file from protected website programmatically with Save As popup

I use WebBrower of microsoft to log into a website. I have no problem with logging in. I don't have the downloadable file url because the file is generated automatically.
How should I download file with out Save As popup to show ?
Work with the DOM (document object model) of the website find your download link via traversing the DOM exposed by the browser control via it's property
Document
it is a tree of elements that your after-login page consists of. There should be some element that you should invoke click on it and then handle OnNavigating (https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.onnavigating(v=vs.110).aspx) event of the control to get the generated download URL.

Loading ASPX markup from database

Let say I have one default.aspx page in local development but in production we have different mark up according to client requirement might be we will not use up-comming.ascx user control on client page but we using on local or using for other client. in short how can load aspx markup from database not .cs code since it is already compiled only change aspx.

SharePoint 2010 Allow Code Blocks for a specific page

I am trying to use C# code in an aspx page within SharePoint 2010. I keep getting the "Code blocks are not allowed" error.
My aspx page located at (server)/SitePages/ajax.aspx: (edited in SharePoint Designer 2010 if it matters)
<%# Page Language="C#" %>
<script runat="server">
Response.Write("Hello world");
</script>
I added the following to web.config at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
Here is the same line that I added to web.config, shown in context:
<SharePoint>
<SafeMode
MaxControls = "200"
CallStack = "false"
DirectFileDependencies ="10"
TotalFileDependencies = "50"
AllowPageLevelTrace = "false"
>
<PageParserPaths>
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
Why do I still get the "Code blocks" error? Is there another security switch somewhere?
(I know custom web parts are the preferred solution, but I don't think that will suffice here because the return value should be json - this is a page to hit via ajax to get data.)
I suppose, you have to define PageParserPath element in an Web application web.config that is located C:\inetpub\wwwroot\wss\VirtualDirectories[application folder]\web.config.
When you upload an aspx page to a document library (which is what you're doing when you use SharePoint Designer) that aspx page can't have inline code blocks and it can't have a code behind. This is primarily a security mechanism. It prevents any old user from uploading an aspx page with malicious content that will then be executed with full privileges on your server, and also serving content to (potentially) any user.
For an aspx page to execute code it needs to be compiled into a WSP and deployed to the GAC on the server. When you do that you can either use inline code blocks or, better yet, have an aspx page with a code behind. To publish that page to the site you would need to compile the project in visual studio into a WSP, deploy that to the server by logging into the machine with sufficient privileges, and then add and deploy the code. This ensures that non-developers can't upload executable code to your site.
Finally, on a more unrelated note, since you don't actually want to display a page, but just JSON content, you probably shouldn't use an aspx page at all (although you can). You should probably just create an HTTP handler or a web service that writes the appropriate content out.

C# variable in .js file from embeded resource in server control ASP.NET

I am building my ASP server control which has some resources. One of them is .js file where i must pass a variable from my ServerControl.cs file.
I know how to for example get resource images in my resource style files and javascript files like this:
var resourceOpen = "<%=WebResource("PatientList.Images.DirOpen.png")%>" ;
var resourceClose = "<%=WebResource("PatientList.Images.DirClose.png")%>";
background: url('<%=WebResource("PatientList.Images.letter-bg.png")%>');
I want to do the same with my public variables in my server control .cs file
Let's say i've got
public string TestVariable = "It works"
How to pass it to javascript file in my resources?
var jsvariable = "<%=TestVariable%>"
Doesn't work. It seems that only WebResource(...) works. When i try to use variables, when I make something like this:
alert("<%=TestVariable%>");
The window with string "<%=TestVariable%>" will appear instead of "It works"
Maybe I'm not understanding your question correctly, but you have a server control that references an external JavaScript file, but in the external file you want to use a property on the control.
If that is what you are asking, then I'm afraid that it's not possible without writing custom handlers or something of the sort. You see, the external JavaScript file is requested by the client seperately from your control execution. At the time the JavaScript file is served by the server, the control has long been destroyed.
Here's what happens:
A request comes to your server for the page
The page loads and creates your usercontrol and a LINK to an external javascript file
The client gets the result from the server
The client sees a link to the external javascript file and requests it from the server
The request for the javascript file comes in on the server
The server gives the client the javascript file
As you can see, there are two requests coming in (step 1 and step 5). In the second request, the one for the javascript file, you no longer have the control with the property available (which was in step 1).
The only way I can think of to get this done is to do something with a custom handler to provide the javascript. This way you can pass any variables as querystring values and have the custom handler insert them into your java script.
I hope this answers your question.

Ajax Client-side framework Error When Running HTML code

I have a aspx page that uses ajax modal popup extender. I run the project successfully from Visual Studio, it works correctly with IE and Firefox as default browsers.
Now I took the html code and created an html file and put in the proper location. When I open the html file by double clicking on it, it is saying script error like “ASP.Net Ajax Client-side framework failed to load”. Why is it happening when I create an HTML file and open it; and not happening when I run the aspx page from Visual Studio. How to overcome it? What should be the best method to take care this in deployment to production?
Note: I have not entered any entries in the Web.Config related to Ajax. We are not using any update panel. We have used ToolkitScriptManager in the aspx page.
Note: There is one more message after this – ‘Sys’ is undefined.
Are the path of microsoft AJAX related JS files still valid/pointing to correct folder after you copy HTML to a location?

Categories

Resources