I am trying to use asp routing in webforms.
want to route home page to defaut.aspx
all other aspx pages to cms.aspx
I made this line of code in global
routes.MapPageRoute(//this for home page
"Home",
string.Empty,
"~/Default.aspx"
);
routes.MapPageRoute("defaultRoute", "{*value}", "~/cms.aspx");//all other pages
this works in localhost
http://localhost:36443 //redirect to default.aspx
http://localhost:36443/page1//redirect to cms.aspx
The problem start here:
http://localhost:36443/page1/somevalue
This time the routing doesn't recognize the physical file(css js... etc) and start routing them to cms.aspx.
in the production website:
http://mySubDomain.website.com
the problem is even more weird ,wcf are routing to cms.aspx.
for example this link:
http://subdomain.website.com/WebServices/webservice.svc/webserviceFunction
redirect to cms.aspx instead of ignore the physical file svn.
I tried all kind of ignore with no effect at all
routes.Ignore("{resource}.svc/{*pathInfo}");
routes.Ignore(("{file}.svn"));
routes.Ignore("{*allcss}", new { allcss = #".*\.css(/.*)?" });
routes.Ignore("{*alljpg}", new { alljpg = #".*\.jpg(/.*)?" });
routes.Ignore("{*svc}", new { alljs = #".*\.svc(/.*)?" });
I think microsoft toke a routing from mvc to webform without single tought about it.
Does anyone know how to go around this problem.
Thanks
Baaroz
you can use
<script type="text/javascript" src='<%= ResolveUrl("~/path to script ")%>'></script>
or
routes.Ignore("{resource}.js/{*pathInfo}");
but you need to write ("the name of folder that you palce js file /{resource}.js/{*pathInfo}");
to can use it
Related
I am trying to use a WebBrowser in a .cs class in a Web Application - NOT A WINDOWS FORM app using (VS 2019).
I know it's a Windows Form app control, but it seems like I should be able to use it in a Web App.
Using WebBrowser in Web App does not have the .Url property, so I just use the .Navigate directly - this is where the code breaks.
I have tried many suggestions on the Net, but nothing seems to work - it looks like most of the examples uses a Web Page - I want to use the WebBrowser directly in code (.cs class).
private static void LoginViaUserAgentFlow()
{
Thread thread = new Thread(delegate ()
{
StringBuilder sb = new StringBuilder(String.Format("{0}/services/oauth2/authorize",
RHOutlook.chosenInstance.sfdcURL));
sb.Append("?response_type=token");
sb.Append(String.Format("&client_id={0}", RHOutlook.chosenInstance.clientId));
sb.Append(String.Format("&redirect_uri={0}", System.Web.HttpUtility.UrlEncode(RHOutlook.chosenInstance.redirectUri)));
WebBrowser webBrowserSFDCLogin = new WebBrowser();
//Here I can't use the .Url becaue it is not available - so I just use
//Navigate to get to the site
webBrowserSFDCLogin.Url = new Uri(sb.ToString());
//This is were it breaks, comes back with error when I navigate to the site.
webBrowserSFDCLogin.Navigate(sb.ToString());
//This code is never reached - failed at above code.
if (webBrowserSFDCLogin.LocationURL != null && webBrowserSFDCLogin.LocationURL.StartsWith(RHOutlook.chosenInstance.redirectUri))
{
//webBrowserSFDCLogin.ScriptErrorsSuppressed = true;
webBrowserSFDCLogin.Stop();
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
I expect to be able to navigate to the external website. If I can navigate to the site if I copy the url directly in a browser (say Chrome).
I tried using ; this gives me the Url property, but still get the error.
You really should stick to suggestions and examples.
What you are trying to do is to use class that is designed for Windows Application inside a Web Application.
Those two frameworks are similar like Earth and Mars. I am afraid you are not going to be able to grow a tree on Mars.
I've seen several MVC4 tutorials that show how to access the index URL for a view, but I can't seem to reach a new view that I add.
I can access my home index at:
http://localhost:3214/
But if I create a new view (let's call it "NewView.cshtml") I can't access it from
http://localhost:3214/NewView.cshtml
Where would it be?
The page inspector expects the page to be at:
http://localhost:4244/Home/NewView
But it isn't there.
UPDATE:
In the solution explorer the file is located at:
MyProject/Views/Home/NewView.cshtml
OK - So think of your Views as merely html files (although they are not) - i.e. they are purely for display purposes. But they are not static like normal HTMLs - they have code.
Hence its the controller and the route that you need to understand.
The route is what you type in the browser. For instance /Home/NewView will be translated to HomeController, NewView action if thats how you have configured it. The default view is {controller}/{action}/{id} so try http://localhost:4244/Home/NewView/1
Now to properly display and code NewView you need to go to your HomeController and add a NewView action. Like:
public ActionResult NewView()
{
return View(); // This will automatically display the NewView.chtml view from the Home (or Shared) folder in your Views folder
}
Then go to your Routes (typically in your global.asax file and add it like:
routes.MapRoute(
"SomeUniqueRouteName",
"Home/NewView",
new { controller = "Home" action = "NewView" }
);
Then you can call it like http://localhost:4244/Home/NewView without the id cause you haev specified a route for it.
Let me know if you need any more help.
Finally after so much testing and so on, i made it works. But i`m confused which files do i need and why im getting an error.
i have
/Scripts/fineupload/
handler.base.js
handler.form.js
handler.xhr.js
uploader.basic.js
util.js
My script bundle is
BundleTable.Bundles.Add(new AmazonS3ScriptBundle("~/bundles/gzip/fineuploader")
.Include("~/Scripts/fineuploader/handler.base.js")
.Include("~/Scripts/fineuploader/handler.form.js")
.Include("~/Scripts/fineuploader/handler.xhr.js")
.Include("~/Scripts/fineuploader/uploader.basic.js")
.Include("~/Scripts/fineuploader/util.js")
);
When i try to load my page im getting an error
My Page
<div id="fine-uploader" class="btn btn-primary"><div>Select Files</div></div>
....
#Scripts.Render("~/bundles/gzip/fineuploader")
...
Fine uploader javascript is rendered as single file ex. somemd5.js
I try to init my uploader on document ready as
uploader = new qq.FineUploaderBasic({
multiple: false,
autoUpload: false,
button: $("#fubUploadButton")[0],
request: {
endpoint: "http://localhost:64247/upload/uploadfile"
},
callbacks: {
onError: errorHandler
}
});
Im getting to much errors, but ill start with the last one..
If i just includeuploader.basic.js, im getting error like
Which files do i need? In zip file from github, there are 10 javascript files (some empty).
Its strange why on test page from zip, everything works but when i implement in my proejct it does not work...
This is precisely why a zip file with combined/minified & version-stamped js, along with version-stamped css & resource files is available. Click on the download link either on the homepage or at the top of the readme in the master branch.
I need to register my css file from code behind. Initialy i used the following code:
CssRegistration.Register("myStyles.css", true);
The problem is, that the file is, like this, expected to be in a folder like 1033/styles within the layout folder. Now there is my problem: For each country (or language region) i need to copy my css into another xxyy/styles-folder. Until now every attempt to solve this situation failed.
What I tried so far
Setting a path:
CssRegistration.Register("/_layouts/myFolder/myStyles.css", true);
This works but if I try to change the theme within Sharepoint, the webpart is not changing anymore.
Using this way:
CssRegistration cssRegistration = new CssRegistration
{
After = "corev4.css",
Name = "/_layouts/MyFolder/myStyles.css",
EnableTheaming = true
};
Controls.Add(cssRegistration);
Same situation over here...
Does anyone know more?
I did like this several times and never had a problem.
First you have to map the Layouts folder in your visual studio project, then insert the CSS over there (but i guess you already did this)
Then you have to do this in your code behind:
CssLink cssLink = new CssLink();
cssLink.DefaultUrl="/_layouts/PROJECTNAME/styles/FILE.css";
if (!this.Page.Header.Controls.Contains(cssLink)) {
this.Page.Header.Controls.Add(cssLink);
}
Regards,
Pedro
Mixit.nl
My friend uses Visual Studio to develop websites in ASP.NET. She only uses the Master Page facility, other than that it's 100% normal HTML and CSS.
Is there a way to export the website to HTML pages based upon their master pages?
If not, it's either loading each page manually and saving the HTML, or I write a little app that does it.
Alternatively, does anyone know of a tool to achieve something similar?
Visual Studio doesn't have this ability out of the box. However, it should be possible to write a tool that walks through a site map, captures the rendered html from the response object, and then write it to a file.
I do not really know how to export an entire site to a local copy.
There are however tool - website downloaders. I know of one - TeleportPro, there should be others. Check them out if it sound as an option to you.
You could give Macromedia Dreamweaver a shot if you feel like experimenting. It caters for Client-side and Server-side page development.
When using MasterPages, the content of the MasterPage is merged with the content page on the server-side (either at pre-compile or the page's first request). So you need to have the content pages and MasterPage compile via aspnet_compile at some point. See the "Runtime Behavior" section of this MSDN article.
Your friend may want to use old fashioned server side includes (which is essentially what a MasterPage is doing for you anyway):
<!--#include virtual="/includes/header.html" -->
<!--#include virtual="/includes/nav.html" -->
<p> content </p>
<!--#include virtual="includes/footer.html" -->
If this is blocked by your web server/host of choice (some disable it for security reasons) then I would create a main index page and use an Ajax call to fill a content DIV. Of course, if Javascript is disabled, your visitors will not see any content.
I think your going to need to roll your own for this one. This function visits a url and gets the contents:
Public Shared Function GetHTTPContent(ByVal url As String) As String
Dim req As WebRequest = System.Net.HttpWebRequest.Create(url)
Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim sr As New StreamReader(req.GetResponse().GetResponseStream(), encode)
Dim HTTPContent As String = sr.ReadToEnd
sr.Close()
sr.Dispose()
Return HTTPContent
End Function
Lots of these exist, here is one:
HTTrack Website Copier
This is also called spidering because it's the same thing search engines do.
Here is my quick solution that crawls your local website for .aspx files and generates .html files next to html.
protected void ButtonGenerate_Click(object sender, EventArgs e)
{
RecursivelyGenerateHtmlFiles(Server.MapPath("~/"), new DirectoryInfo(Server.MapPath("~/")));
}
private void RecursivelyGenerateHtmlFiles(string root, DirectoryInfo folder)
{
foreach (var aspxPage in folder.GetFiles("*.aspx"))
{
var destination = aspxPage.FullName.Substring(0, aspxPage.FullName.Length - 4) + "html";
if (File.Exists(destination))
File.Delete(destination);
var url = "http://" + Request.Url.Authority + "/" + aspxPage.FullName.Replace(root, "");
var request = HttpWebRequest.Create(url);
File.WriteAllText(destination, new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd());
}
foreach (var subDirectory in folder.GetDirectories())
{
RecursivelyGenerateHtmlFiles(root, subDirectory);
}
}
Worked for me.
Also, you can edit a .bat file to generate a folder with all the .html files from your site. This is useful when giving creative a flat copy.
set folder="Generated"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd /d ..
xcopy /r /d /i /s /y /exclude:exclude.txt PAHtml Generated
Here is the exclude.txt file to use
.dll
.cs\
.aspx
.pdb
.csproj
.user
.vspscc
.config