That did get me closer; I now have the functionality I need but it required another filter and module. Now I just need to get them to play nice together. Thanks!
------------------- abort, retry, fail?
That did get me closer; I now have the functionality I need but it required another filter and module. Now I just need to get them to play nice together. Thanks!
------------------- abort, retry, fail?
Hello all, I currently have an httpmodule that extracts various information regarding the response that is being sent to the client. One thing I want to implement is a count of how many external files (.js or .css) are being included in the page. I have a regex function for this, but the problem I'm having is I can't quite figure out how to access the markup that is being sent to the client. Here's most of what I have so far:
public class ResponseSizeHttpModule : IHttpModule
{
public void Init(HttpApplication application)
{
if (Convert.ToBoolean(ConfigurationManager.AppSettings\["CheckResponseSize"\]) == true)
{
application.BeginRequest += new EventHandler(this.AddFilter);
application.EndRequest += new EventHandler(this.ResponseMessage);
}
}
private void AddFilter(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
application.Response.Filter = new CounterClass(application.Response.Filter);
}
private void ResponseMessage(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
long lPageSize = application.Response.Filter.Length;
long lRespLimit = Convert.ToInt64(ConfigurationManager.AppSettings\["ResponseLimitBytes"\]);
if (lPageSize > lRespLimit)
{
**string strResponse = ""; //get the content of the response here!**
int intNumIncludes = CountIncludes(strResponse);
//StringBuilder sbAlertMsg = new StringBuilder();
//build message here
//HttpContext.Current.Response.Write(sbAlertMsg);
}
}
private int CountIncludes(string strResponse)
{
Regex reScripts = new Regex(".js|.css", RegexOptions.IgnoreCase);
return reScripts.Matches(strResponse).Count;
}
public void Dispose(){}
}
The bolded part is where I'd like to try to do this. I'm pretty new to httpmodules and the like so any suggestions on more effective methods are welcome, as would any other help. Thanks in advance!
------------------- abort, retry, fail?
My guess is that it sounds like they're associating usernames with IP addresses.
------------------- abort, retry, fail?
Hello all, I'm in the process of writing an HTTP Module that will determine the size of the response and display it. I'm pretty new the http module thing so there's probably a good way to do this that I haven't found yet, but I've tried everything I can think of. Here's what I have so far:
public class ResponseSizeHttpModule : IHttpModule
{
public int RespSize;
public void Init(HttpApplication application)
{
application.PreSendRequestHeaders += new EventHandler(this.ResponseCheck);
application.EndRequest += new EventHandler(this.ResponseMessage);
}
private void ResponseCheck(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
**StreamReader reader = new StreamReader(context.Response.OutputStream);**
reader.ReadToEnd();
reader.Close();
byte\[\] buffer = System.Text.Encoding.UTF8.GetBytes(reader.ToString());
RespSize = buffer.Length;
}
private void ResponseMessage(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("Page size: " + RespSize + " bytes.");
}
public void Dispose(){}
}
So far, the message comes up but the page size is always 0, so that's not right. It's come to my attention that the bold part that OutputStream is write-only, if I understand this correctly. How would I go about intercepting what's being written to the OutputStream so I can determine its size? Like I said, my knowledge of this particular facet of .Net isn't all that great, so if anyone can recommend a good method or alternative, I'd be glad to hear it. Thanks in advance, Jan
------------------- abort, retry, fail?
Hey All, I'm having a bit of a problem with loading some images using javascript. What I'm trying to do is parse out a query string value, and load an image using that value. For instance, if someone went to: http://www.mydomain.com?person=JohnDoe It would parse out the name from the query string and load JohnDoe.gif into a image named portrait and write a cookie with that information; if there were no query string value, it would would load a default image. Now, this works in Firefox, but not IE; IE just results in that irritating little red "X" broken image box. My Javascript: ======================== //get name from GET string function GetName(CookieKey) { //try to read the key "name" value from cookie var personalimg = readCookie('name') if (personalimg) //if the cookie exists, load the image with the same name { //this appears to be the part that isn't working in IE only (firefox is fine) //I have checked the image paths and the files do exist document.contact.src="./images/people/" + personalimg + "Contact.gif"; } else // if no cookie, check for name in query string or load default image { var query = window.location.search.substring(1); var pair = query.split("="); //if the cookie contains the key name, load it's value into the image if (pair[0] == CookieKey) { document.contact.src="./images/people/" + pair[1] + "Contact.gif"; document.cookie = "name=" + pair[1] + ";" } else //load default image { document.contact.src = "./images/Contact.gif"; } } } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } ================== My HTML: ================== ) Note that I don't use Javascript too often so any suggestions on how to improve this would be much appreciated, as is any other help. Thanks in advance! ------------------- abort, retry, fail?
Hello everyone, Recently I've inherited the maintenance of an application who's database contains and image column. I've received a few requests to update a few records, but I've never worked with image-typed columns before, and unfortunately the source code for the application is unavailable to me. I have the files I need to update the table with on my local machine - what would be the best way to get them into the table? Thanks in advance for any help.
------------------- abort, retry, fail?
Hello all, I'm using a vb.net function to write some javascript to a literal control. That part works just fine. However, the javascript I'm writing is supposed to write the return value of a confirmation dialogue to a hidden input to reference later. I can reference the hidden input fine, but it always contains the default value - it seems that the javascript never writes to it. Here's my hidden field and literal control: <asp:Literal id="ltAlert" runat="server" EnableViewState="false" /> Here's my vb function: Function GetConfirmation(ByVal strVerb As String) As Sring ltAlert.Text = "document.getElementById('hdnbox').value = window.confirm('Are you sure you want to " & strVerb & " these requests?');" Return hdnbox.Value.ToString() End Function It always returns "hello!", instead of the true or false that one would expect. It has to be something really tiny and stupid that I'm looking right over. Note I've also tried variations along the lines of var answer = window.confirm("blah"); document.getElementById('hdnbox') = answer; to no avail. Also worthy of note it seems to be returning the value before the user has had the chance to interact with the dialogue. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
Hello everyone, I'm looking for a way to trigger a javascript confirmation dialog box and capture its value via a function as opposed to button events (as per all the tutorials I've found). The reasoning behind this is that are are 3 separate things that could trigger this dialog - 2 being button events, and one being page load if certain circumstances are met. Needless to say I don't want to write 3 separate functions for these if I don't have to, I'd rather just call the main confirm function from pageload and/or the button event handlers as appropriate. Does anyone have any ideas? Thanks in advance!
------------------- abort, retry, fail?
I've found sometimes for whatever reason, Visual Studio sometimes disassociates button events. Usually all it takes for me to fix is to put in a Response.Write("button clicked") in the event handler. That usually gets things going, then you can just erase or comment out that line. It's some kind of wacky VS voodoo. ------------------- abort, retry, fail?
Hello all, This is a kind of goofy situation I have here. Let me Try to break it down as best as I can: Page1.aspx - has a masterpage define - includes page2.html that is in a subdirectory (<!-- #include virtual="JavaStuff/Page2.html" -->
) Page2.html - contains the JavaStuff.class applet that is located in the same directory Now, when I navigate to Page1 the java console returns me a JavaStuff.class not found error. When I navigate directly to Page2 everything works fine. I've tried using absolute paths in the applet declaration but that breaks both pages.:confused: The reason I don't put the applet directly in the Page1 is because the HTML of Page2 contains some pretty odd-ball stuff that I don't want to break if I can avoid it. Any ideas or suggestions? Thanks in advance. ------------------- abort, retry, fail?
D'oh, that makes sense! Thanks! ------------------- abort, retry, fail?
Usually you can copy your entire application folder to C:\Inetpub\wwwroot on the test machine. You will need IIS installed on the target machine and you may have to register it as an application in IIS, though. ------------------- abort, retry, fail?
Hello everyone, I have a datagrid in with there is a linkbutton that uses the ItemCommand. When this is clicked, I would like to open a new window and pass the page in the new window the datakeyfield value of the row in which the button was clicked. I've done similar things before with just a link button by itself, along the lines of: lnkButton.Attributes("onClick") = "window.open('mypage.aspx?RowID=" & intRowID & ")"
But I'm having a hard time figuring out how to adapt that to work from within a datagrid. Any pointers would be greatly appreciated. Thanks in advance! ------------------- abort, retry, fail?
Hello everyone, I have a table set up to look like a box with 4 tabs. There are two classes of tabs, tabactive and tabinactive. tabactive has a white background, black border on the top, left, and right, and a white border on the bottom. tabinactive has a gray background, and a black border on all sides. The problem I'm having is that in Firefox when I click the link that activates the javascript function to change the class of the table cell/tab, the background color changes correctly but the bottom border change doesn't always stick. I'll get tabactive tabs with black bottom borders, and tabinactive cells with white bottom borders - everything else works fine. Oddly enough, this only seems to happen for the last 2 cells/tabs (see HTML below). Here's my CSS: .tabactive { border: solid 1px black; border-bottom: solid 1px white; background-color: #FFFFFF; text-align: center; padding: 0px; margin: 0px; } .tabinactive { border: solid 1px black; border-bottom: solid 1px black; background-color: #CCCCCC; text-align: center; padding: 0px; margin: 0px; } Here's my javascript: /* set visibility of divs and change bg color of tabs */ function TabClick(LinkName) { for (var x = 1; x < 5; x++) //only allows for 4 tabs right now { TabID = "Tab" + x //assign names w/ increment that match elements DivID = "Div" + x //i.e. Tab1, Div2, etc Tab = document.getElementById(TabID) //grab elements Div = document.getElementById(DivID) if (TabID != LinkName) //set style and vis of unselected tabs + divs { Tab.className = "tabinactive" Div.style.visibility = "collapse" Div.style.display = "none" } else //set style and vis of selected tabs + divs { Tab.className = "tabactive" Div.style.visibility = "visible" Div.style.display = '' }//end else }//end for }//end function Here's my HTML (note that this happens almost exclusively on Tab3 and Tab4):
This is Div1.
Thi
That gave me an awesome idea that worked out great. In case anyone's interested, here's what I did: 1. saved my query string as a session variable 2. added an attribute to my link button that triggered the print to open a new window 3. opened a new window that containted print.aspx on click, that did the follwing: - populated a datagrid from the query string session variable - registered a client script that: - called window.print() - called window.close() Thanks for your help! ------------------- abort, retry, fail?
You should put something like this in your code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'this checks to see if the page has been posted back, i.e. submit has been clicked If IsPostBack Then Try MyInsertFunction() 'calls your insert function MyEmailFunction() 'calls your email function Catch ex As Exception Response.Write(ex) 'if either of the above operations fail, this will tell you the error End Try End If End Sub
Alternately, you can place that try/catch block inside of your submit button click event handler instead of Page_Load. Hope that helps. ------------------- abort, retry, fail?
Hello everyone, I have an excel file in the same directory as my .aspx page and I need it to printed to the user's default printer (after whatever necessary dialogs) when a button is clicked. All the tutorials I've found are windows forms examples are pretty clunky and I'm not quite sure how to transfer them over the to context of web forms. If anyone could give me any pointers or links to examples, I would be most appreciative. Thanks in advance! ------------------- abort, retry, fail?
Hello everyone, I'm currently writing a app that uses MySQL. However, I'm having trouble connecting to my database. I'm running the tests from my local machine and I *DO* have the MySQL Connector .Net 1.0.7 driver installed and the ODBC namespace imported. This is the connection string I'm using: Driver={MySQL ODBC 3.51 Driver};server=myserver.myhost.com;user id=myusername; password=mypassword; database=mydatabase; pooling=false This is the error I'm receiving: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Any ideas? I've looked throught quite a few tutorials and I seem to be doing everything that they say correctly. Thanks in advance for any help! ------------------- abort, retry, fail?
I'm pretty sure, because when I do a test page using a codebehind page and use the same import path in the code behind instead of in it works fine. i.e. <code><%@ Import Namespace="txtCMS.TextFileReader" %></code> < -- (before <script>) does not work vs. <code>Imports txtCMS.TextFileReader</code> <-- (in code behind) works ------------------- abort, retry, fail?</x-turndown>
Ah well that might be part of my problem. My TextReader is a custom class, so I guess renaming it would be in order so as to avoid any confusion. So now I'm doing this at the very beginning of the document and I'm still getting the same error: <%@ Page Language="vb"%> <%@ Import Namespace="txtCMS.MyTextFileReader" %> Private Sub Page_Load() <b>Dim Reader as New MyTextFileReader</b> (BC30002: Type 'MyTextFileReader' is not defined.) Label1.Text = Reader.Extract("test.txt") End Sub
Any other ideas? ------------------- abort, retry, fail?