I have an asp.net application and in that I have a html page.
I need to get the Windows username in that html page.
I understand its not possible in normal page.
I need to achieve this without using ActiveX objects.
you will need to create an AJAX call on your page to some WebMethod in your ASP.NET application that call will return you user name.
it basicaly comes down to placeing request to the WebMethod like this
the call below gets data from WebMothod and displays it in the div in the page
$.get('jqueryintro.htm', function (data) {
$('#maindiv').html(data);
});
If you will need more information you can use this page very easy to follow article.
And don't forget to include jQuery ($) in your page
Assuming you have Windows authentication enabled on the site and the user is authenticated you can put this in your ASPX:
<p><%= User.Identity.Name %></p>
The above code embeds the username in the HTML that is sent to the client.
An AJAX request is not required.
Try something like this...
<div runat="server"><%= System.Security.Principal.WindowsIdentity.GetCurrent().Name %></div>
<div runat="server"><%= User.Identity.Name %></div>
<div runat="server"><%= Request.ServerVariables["LOGON_USER"].ToString() %></div>
As long as you are using Windows Auth it should work, otherwise you would just get the account info for whatever IIS is running under.
Any container with runat="server" should work really it doesn't have to be a div.
Related
I'm trying to write a spider that will automatically log in to this website. However, when I try using scrapy.FormRequest.from_response in the shell I get the error:
No <form> element found in <200 https://www.athletic.net/account/login/?ReturnUrl=%2Fdefault.aspx>
I can definitely see the form when I inspect element on the site, but it just did not show up in Scrapy when I tried finding it using response.xpath() either. Is it possible for the form content to be hidden from my spider somehow? If so, how do I fix it?
The form is created using Javascript, it's not part of the static HTML source code. Scrapy does not parse Javascript, thus it cannot be found.
The relevant part of the static HTML (where they inject the form using Javascript) is:
<div ng-controller="AppCtrl as appC" class="m-auto pt-3 pb-5 container" style="max-width: 425px;">
<section ui-view></section>
</div>
To find issues like this, I would either:
compare the source code from "View Source Code" and "Inspect" to each other
browse the web page with a browser without Javascript (when I develop scrapers I usually have one browser with Javascript for research and documentations and another one for checking web pages without Javascript)
In this case, you have to manually create your FormRequest for this web page. I was not able to spot any form of CSRF protection on their form, so it might be as simple as:
FormRequest(url='https://www.athletic.net/account/auth.ashx',
formdata={"e": "foo#example.com", "pw": "secret"})
However, I think you cannot use formdata, but instead they expect you to send JSON. Not sure if FormRequest can handle this, I guess you just want to use a standard Request.
Since they heavily use Javascript on their front end, you cannot use the source code of the page to find these parameters either. Instead, I used the developer console of my browser and checked the request/response that happened when I tried to login with invalid credentials.
This gave me:
General:
Request URL: https://www.athletic.net/account/auth.ashx
[...]
Request Payload:
{e: "foo#example.com", pw: "secret"}
Scrapy has a JsonRequest class to help with posting JSON. See here [https://docs.scrapy.org/en/latest/topics/request-response.html]
So something like the below should work
data = {"password": "pword", "username": "user"}
# JSON POST to API login URL
return JsonRequest(
url=url,
callback=self.after_login,
data=data,
)
I have a simple question about links in HTML emails
I am trying to add a simple dynamic link in an HTML email to my site like this
MySite
This fails, but this works
MySite
I am assuming its to do with the embedded ruby but strangely, the links work if I view them on my iphone.
Any thoughts on this?
Stupid me....
I needed to construct the link using the ActionMailer generating URLs instructions, see here http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
My URL is
<%= link_to "View response", notification_micropost_response_url(#micropost, #response) %>
The default host must be first set in the dev and prod environment config files:
Example (development.rb)
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
I have the following VBS code in my webpage:
<body>
<%
Randomize
response.write(Rnd)
%>
</body>
But instead of outputting a random number, I get a webpage that says this:
<% Randomize response.write(Rnd) %>
Why won't my code execute?
Thank you.
You need to make sure your webpage extension is managed by the ASP handler mapping. The steps to configure handler mappings depend on the version of IIS you are using.
See this page for information on configuring ASP under IIS 7 or 7.5.
I have a very simple JSP page first.jsp that gives reference to so many other JSP pages through hyperlink.
I am trying to pass a value through the hyperlink in first.jsp and retrieve it in second.jsp using request.getparameter().
I used:
Second JSP
and in the second.jsp page I used:
alert( "value = " + <%= request.getParameter("value") %>);
but when I try to run the code and click on Second JSP I get a 404 page not found error for:second.jsp?value=1
It looks like your URL to second JSP might not be good. "second.jsp" is not visible to your web app server the way you specified.
To fix this:
If your jsps are resolved through a web app try:
Second JSP
if you have jsp or similar directory that is visible outside of web app context do something like:
Second JSP
Try getQueryString() method to access the value that you passed through the URL.
Then use string methods to extract the value form the URL.
For example, you pass the parameter as you mentioned
Use getQueryString() method in second.jsp, it will return the string value = 1 as the result.
Html:
<a href="birth1.jsp?key=14APR010315381">
<center>
<font size="2" color="black">MIKE LOBO</font></center>
</a>
Jsp:
request.getParameter("key");
I m using in my project and its working fine
I have implemented paypal in my web page. Process is 'given inputs are redirect to other page(2 nd page) which have to get that input and redirect to paypal page(third page). Here we submit data on first page. value pass to second page(in this page user interaction not allowed) after pass to third page.It works fine in IE . But Not In Mozila.Send any Solution.
Code sample(second page):
<%string product = Request.QueryString["productName"].ToString();%>
<% string amount = Request.QueryString["price"].ToString(); %>
">
">
document.all.frmpaypal.submit();
Fine in IE, Not In Mozila
document.getElementById("frmpaypal").submit();
document.all is an IE-only non-standard extension. You can use:
document.getElementById("frmpaypal").submit();
Which will work on both browsers. Better yet, use something like jQuery:
$("#frmpaypal").submit();
(This simple example doesn't really show you the power of jQuery, but you'll love it once you find out everything it can do!)
document.all is non-standard. Add an ID and use document.getElementById.
Have you checked into the possibility of sending values via GET instead of POST in the FORM's action attribute?